#!/bin/bash
# Author: liuxu
# Date: 2025/8/29
# Description: 官方rccl-test测试用例(https://github.com/ROCm/rccl-tests.git)
# Usage method: ./rccl-tests-auto.sh > results-rccl-trace-test-`date +"%Y%m%d"`.log 2>&1 &

########################################
# 测试脚本与rccl-tests/build保持同一目录
SCRIPT_DIR=$(dirname $(realpath "$0"))
echo "Current directory: $SCRIPT_DIR"
echo "which hipprof: $(which hipprof)"

# 保存结果目录
RESULT_ROOT="$SCRIPT_DIR/results-rccl-trace-test"
mkdir -p "$RESULT_ROOT"


########################################
# 定义所有测试用例
TEST_CASES=(
    all_gather_perf
    all_reduce_perf
    alltoall_perf
    alltoallv_perf
    broadcast_perf
    gather_perf
    reduce_perf
    reduce_scatter_perf
    scatter_perf
    sendrecv_perf
)

# 循环执行所有测试用例
for test in "${TEST_CASES[@]}"; do
    echo "==================================== $test ============================================"
    # 创建测试结果目录
    test_result_dir="$RESULT_ROOT/$test"
    mkdir -p "$test_result_dir"
    cd "$test_result_dir" || { echo "Failed to enter the directory: $test_result_dir"; continue; }

    # 执行测试
    hipprof --rccl-trace "$SCRIPT_DIR/build/$test" -b 8 -e 1G -f 2 -g 4
done


# 打包测试结果
# zip results-rccl-trace-test-`date +"%Y%m%d"`.zip results-rccl-trace-test*
